cmake_minimum_required(VERSION 3.18.1)
project(shadowhook)

if(${ANDROID_ABI} STREQUAL "arm64-v8a")
    set(ARCH "arm64")
elseif(${ANDROID_ABI} STREQUAL "armeabi-v7a")
    set(ARCH "arm")
endif()

set(TARGET "shadowhook")
set(SOURCEDIR ${CMAKE_SOURCE_DIR}/shook/)

file(GLOB SRC ${SOURCEDIR}*.c ${SOURCEDIR}arch/${ARCH}/*.c ${SOURCEDIR}common/*.c ${SOURCEDIR}third_party/*/*.c)
add_library(${TARGET} ${SRC})
target_compile_options(${TARGET} PRIVATE -std=c11 -Weverything -Werror)
target_include_directories(${TARGET} PUBLIC ${SOURCEDIR} ${SOURCEDIR}include ${SOURCEDIR}arch/${ARCH} ${SOURCEDIR}common ${SOURCEDIR}third_party/xdl ${SOURCEDIR}third_party/bsd ${SOURCEDIR}third_party/lss)
target_link_libraries(${TARGET} log)

if(USEASAN)
    target_compile_options(${TARGET} PRIVATE -fsanitize=address -fno-omit-frame-pointer)
    target_link_options(${TARGET} PRIVATE -fsanitize=address)
else()
    #target_compile_options(${TARGET} PRIVATE -Oz -flto -faddrsig -ffunction-sections -fdata-sections)
    #target_link_options(${TARGET} PRIVATE -Oz -flto -Wl,--icf=all -Wl,-mllvm,--enable-machine-outliner=always -Wl,--exclude-libs,ALL -Wl,--gc-sections -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/shadowhook.map.txt)
endif()
